package com.md.model.html;

import com.md.value.html.LabelAttributeType;
import com.md.value.html.Unit;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Optional;

/**
 * @author 刘骄阳
 * 2024-05-15 23:39
 */
@Getter
@AllArgsConstructor(staticName = "of")
public class LabelAttribute {
  private final LabelAttributeType attribute;
  private final Object value;
  private final Unit unit;

  public static LabelAttribute of(final LabelAttributeType attribute,
                                  final Object value) {
    return LabelAttribute.of(attribute, value, null);
  }

  public String getAttributeCode() {
    return String.format(" %s=%s%s ", attribute.getAttributeName(), value,
      Optional.ofNullable(unit).map(Unit::getValue).orElse(""));
  }

  public String getAttributeName() {
    return attribute.getAttributeName();
  }
}
